package org.planaz.campusvoting.config;

import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class MailConfiguration {

        @Bean
        public JavaMailSenderImpl JavaMailSender(){
            JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
            mailSender.setHost("smtp.qq.com");
            mailSender.setUsername("1781088254@qq.com");
            mailSender.setPassword("tmrcynpkheucccjg");
            mailSender.setDefaultEncoding("UTF-8");
            Properties properties = getProperties();
            mailSender.setJavaMailProperties(properties);

            return  mailSender;
        }

    @NotNull
    private static Properties getProperties() {
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.auth", "true");//开启认证
        properties.setProperty("mail.smtp.timeout", "200000");//设置链接超时
        properties.setProperty("mail.smtp.port", Integer.toString(25));//设置端口
        properties.setProperty("mail.smtp.socketFactory.port", Integer.toString(465));//设置ssl端口
        properties.setProperty("mail.smtp.socketFactory.fallback", "false");
        properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        return properties;
    }
}
